<template>
  <div class="app-container">
    <el-form @submit.native.prevent :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="120px" :label-position="labelPosition">
      <el-form-item label="单据类型" prop="dzlb">
        <el-select
            v-model="queryParams.dzlb"
            placeholder="请输入单据类型"
            clearable
            @change="changeOrderType"
            filterable
        >
            <el-option
                v-for="(item, index) in orderType"
                :key="index"
                :label="item.label"
                :value="item.value"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="客户" prop="khmc">
        <el-select
            v-model="queryParams.khmc"
            placeholder="请输入客户"
            clearable
            @change="changeselectClient5"
            filterable
            :loading="selectClient5Loading"
        >
            <el-option
                v-for="(item, index) in client3List"
                :key="index"
                :label="item.khmc"
                :value="item.khmc"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="条码" prop="sptm">
        <el-input
          v-model="queryParams.sptm"
          placeholder="请输入条码"
          clearable
          @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="柜号/批号" prop="spgh">
        <el-input
          v-model="queryParams.spgh"
          placeholder="请输入柜号/批号"
          clearable
          @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item label="仓库" prop="spckid">
        <el-select
            v-model="queryParams.spckid"
            placeholder="请选择"
            clearable
            @change="changeWarehouse"
            filterable
            :loading="selectWarehouse16Loading"
        >
            <el-option
                v-for="item in warehouseList"
                :key="item.spckid"
                :label="item.spckmc"
                :value="item.spckid"
            />
        </el-select>
      </el-form-item>
      <el-form-item label="业务发生日期" prop="goodsOccurrenceDate">
        <el-date-picker
          v-model="goodsOccurrenceDate"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="goodsOccurrenceDateChange()">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="物品规格" prop="spzs">
        <el-input
          v-model="queryParams.spzs"
          placeholder="请输入关联单号"
          clearable
          @keyup.enter.native="enterClick"
        />
      </el-form-item>
      <el-form-item>
        <el-checkbox v-model="queryParams.jqcz" label="精确搜索" true-label="1" @change="getList"></el-checkbox>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="getList">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain size="mini" @click="handleExport" v-hasPermi="['zhcloud:sjzl:export']">导出Excel</el-button>
      </el-col>
    </el-row>
    <el-table
      v-loading="loading"
      :data="goodsOccurrenceList"
    >
      <af-table-column prop="dzopmc" label="单据类型" fixed="left"></af-table-column>
      <af-table-column prop="pzbh" label="单据编号"></af-table-column>
      <af-table-column prop="sptm" label="客户条码"></af-table-column>
      <af-table-column prop="sptmc" label="仓库条码"></af-table-column>
      <af-table-column prop="spckmc" label="仓库"></af-table-column>
      <af-table-column prop="ckcw" label="仓位"></af-table-column>
      <af-table-column prop="spjs" label="件数"></af-table-column>
      <af-table-column prop="spjsl" label="单重(KG)"></af-table-column>
      <af-table-column prop="spsl" label="重量(吨)"></af-table-column>
      <af-table-column prop="ssrqid" label="初次入仓日期"></af-table-column>
      <af-table-column prop="ssrqidn" label="业务发生日期"></af-table-column>
      <af-table-column prop="spckmc2" label="调拨仓库"></af-table-column>
      <af-table-column prop="ckcw2" label="调拨仓位"></af-table-column>
      <af-table-column prop="khmcn" label="新货权人"></af-table-column>
      <af-table-column prop="iszxf" label="装卸费"></af-table-column>
      <af-table-column prop="iszyl" label="作业量"></af-table-column>
      <af-table-column prop="prrq" label="创建时间"></af-table-column>
      <af-table-column prop="khmc" label="客户"></af-table-column>
      <af-table-column prop="dzbz" label="单据备注" width="150" :show-overflow-tooltip="true"></af-table-column>
      <af-table-column prop="spzs" label="物品规格"></af-table-column>
      <af-table-column prop="spcd" label="品牌"></af-table-column>
      <af-table-column prop="spgh" label="柜号"></af-table-column>
      <af-table-column prop="spbh" label="批号"></af-table-column>
      <af-table-column prop="itbz" label="备注" width="150" :show-overflow-tooltip="true"></af-table-column>
      <af-table-column prop="wpggA" label="纱支"></af-table-column>
      <af-table-column prop="wpggB" label="工艺"></af-table-column>
      <af-table-column prop="wpggC" label="工序"></af-table-column>
      <af-table-column prop="wpggD" label="用途"></af-table-column>
      <af-table-column prop="wpggE" label="产地"></af-table-column>
      <af-table-column prop="wpggF" label="漂染性"></af-table-column>
      <af-table-column prop="wpggG" label="生产日期"></af-table-column>
      <af-table-column prop="wpggH" label="颜色"></af-table-column>
      <af-table-column prop="deli" label="删除状态"></af-table-column>
    </el-table>
     <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="getList"
      />
  </div>

</template>

<script>
import { getGoodsOccurrenceList } from "@/api/storage/dataOverview/goodsOccurrence"
import { selectWarehouse16 } from "@/api/storage/warehouse"
import { selectClient5 } from "@/api/storage/customer"
import { formatDate } from '@/utils'

export default {
  name: "GoodsOccurrence",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //表格加载
      loading:true,
       //对齐
      labelPosition: "right",
      //客户加载
      selectClient5Loading:true,
      //仓库加载
      selectWarehouse16Loading:true,
      goodsOccurrenceDate:[],
      //单据类型
      orderType: [
        {label:"入仓单", value:"ck_spdjin"},
        {label:"出仓单", value:"ck_spdjout"},
        {label:"调仓单", value:"ck_spdjDB"},
        {label:"货转单", value:"ck_spdjZY"},
        {label:"质押单", value:"ck_spdjZJ"}
      ],
      // 查询参数
      queryParams: {
        dat1: "",
        dat2: "",
        khmc: "",
        dzlb: "",
        spgh: "",
        spzs: "",
        spckid: "",
        sptm: "",
        jqcz: "",
        downloadType:"json"
      },
      //获取客户参数
      selectClient5Query: {
        name1:""
      },
      // 货物入仓列表
      goodsOccurrenceList: [],
      //仓库列表
      warehouseList:[],
      //客户列表
      client3List: [],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  beforeRouteEnter(to, from, next) {
    const params = to.params
    next(vm => {   
      if(Object.keys(params).length > 0) {
        if(to.params.refresh == true) {
          vm.getList()
        }
      }
    })
  },
  created() {
    const nowDate = formatDate(Date.now()).split(" ")[0]
    this.queryParams.dat1 = nowDate
    this.queryParams.dat2 = nowDate
    this.goodsOccurrenceDate = [nowDate,nowDate]
    this.getWarehouse()
    this.getClient3()
    this.getList()
  },
  methods: {
     /**获取客户 */
    getClient3() {
      this.selectClient5Loading = true
      selectClient5(this.selectClient5Query).then(response => {
        this.client3List = response.data
        this.selectClient5Loading = false
      });
    },
    /**获取仓库 */
    getWarehouse() {
      this.selectWarehouse16Loading = true
      selectWarehouse16({}).then(response => {
        this.warehouseList = response.data
        this.selectWarehouse16Loading = false
      });
    },
    /** 查询货物发生明细 */
    getList() {
      this.loading = true
      getGoodsOccurrenceList(this.queryParams, {pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.goodsOccurrenceList = response.rows;
        this.total = response.total;
        this.loading = false
      });
    },

    /**选择仓库 */
    changeWarehouse() {
      this.getList()
    },
    /**导出所有 */
    handleExport() {
      this.download('/storage/sjzl/export1', this.queryParams, `货物发生明细_${new Date().getTime()}.xlsx`)
    },

    /**选择单据类型 */
    changeOrderType() {
        this.getList()
    },

    /**选择客户 */
    changeselectClient5() {
        this.getList()
    },

     /**选择入仓时间 */
    goodsOccurrenceDateChange() {
      this.queryParams.dat1 = this.goodsOccurrenceDate?this.goodsOccurrenceDate[0]:""
      this.queryParams.dat2 = this.goodsOccurrenceDate?this.goodsOccurrenceDate[1]:""
      this.getList()
    },

    /**enter键触发 */
    enterClick(e) {
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.reset()
      this.getWarehouse()
      this.getClient3()
      this.getList()
    },
    reset() {
      Object.assign(this.$data, this.$options.data())
    },
  }
};
</script>
